package cn.ml.web1662.web.servlet;

import cn.ml.web1662.service.StudentService;
import cn.ml.web1662.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class CheckNameServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        StudentService service = new StudentServiceImpl();
        PrintWriter out = resp.getWriter();
        if(service.findByName(name)){
            //被占用
            out.println("被占用");
        }else{
            //可以使用
            out.println("可以使用");
        }
        out.flush();
        out.close();
    }
}
